package com.lighu.computing;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.linghu.util.CoCount;
import com.linghu.util.HeatConsumer;

public class MainActivity extends AppCompatActivity {
    private ImageView[] img=new ImageView[12];
    private int[] imagePath=new int[]{
        R.mipmap.img01,R.mipmap.img02,R.mipmap.img03,R.mipmap.img04,
            R.mipmap.img05,R.mipmap.img06,R.mipmap.img07,R.mipmap.img08,
            R.mipmap.img09,R.mipmap.img10,R.mipmap.img11,R.mipmap.img12
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
        setContentView(R.layout.convert_main);
//        GridLayout layout = findViewById(R.id.layout);
//        for (int i=0;i<imagePath.length;i++){
//            img[i]=new ImageView(MainActivity.this);
//            img[i].setImageResource(imagePath[i]);
//            img[i].setPadding(2,2,2,2);
//            ViewGroup.LayoutParams params=new ViewGroup.LayoutParams(200,200);
//            img[i].setLayoutParams(params);
//            layout.addView(img[i]);
//
//        }
    }
    public void myButtonClicked(View view) {
        // 在这里编写按钮点击事件的处理逻辑
        TextView inputText = findViewById(R.id.edit_text);
        TextView outputText = findViewById(R.id.edits_co);
        TextView outputHeatText = findViewById(R.id.edits_heat);

//        String value = inputText.getText().toString();
        inputText.setInputType(InputType.TYPE_CLASS_NUMBER); // 设置输入类型为整数
        int value = Integer.parseInt(inputText.getText().toString());
        //公式代码的转换--->引入轮子
        HeatConsumer consumer = new HeatConsumer();//生成热量【1】
        double heatValue = consumer.heatCount(value, 25, 1, 165, 45, 30);
        String heatsValue = Double.toString(heatValue);
        CoCount coCount = new CoCount();//生成二氧化碳【2】
        double co = coCount.countCo(value, 25, 1, 165, 45, 30);
        String co2 = Double.toString(co);
        outputText.setText(co2);//热量
        outputHeatText.setText(heatsValue);//二氧化碳
    }
}